<div class="funcbar">
<span class="add"><i class="fa fa-plus"></i> 新增</span>
<span class="edit"><i class="fa fa-pencil"></i> 编辑</span>
<span class="role"><i class="fa fa-user-plus"></i> 设置角色</span>
<span class="del"><i class="fa fa-minus"></i> 删除</span>
<span class="forbidden"><i class="fa fa-stop"></i> 停用</span>
<span class="enable"><i class="fa fa-play"></i> 启用</span>
<span class="print"><i class="fa fa-print"></i> 打印</span>
<span class="resetPwd"><i class="fa fa-key"></i> 重置密码</span>
<span class="detail"><i class="fa fa-bars"></i> 详细</span>
<span data-toggle="collapse" data-target="#userS"> <i class="fa fa-search-plus"></i> 查询</span>
</div>
<div id="userS" class="searchbar panel panel-collapse collapse" role="tabpanel" aria-expanded="true">
<form class="searchform" role="form">
<div class="line" >
<div class="col-245 input-group">
<span class="input-group-addon">用户姓名</span><input type="text" class="form-control" name="name" placeholder="模糊查询">
</div>
<div class="col-245 input-group">
<span class="input-group-addon">手机号码</span><input type="text" class="form-control" name="mobile" placeholder="模糊查询">
</div>
<div class="col-245 input-group">
<span class="input-group-addon">电子邮箱</span><input type="text" class="form-control" name="email" placeholder="精确查询">
</div>
<div class="col-245 input-group">
<span class="input-group-addon">用户状态</span><select name="status" class="form-control"><option value="">请选择</option></select>
</div>
</div>
<div class="text-center" >
<input type="hidden" name="page" value="1"> 
<button  type="button" data-toggle="collapse" data-target="#userS">关闭</button> 
<button  type="reset" class="button" >清空</button> 
<button  type="button" class="searchbtn" >查询</button> 
</div>
</form>
</div>
<div id="userD" class="data-list">
<table class="table table-hover">
<thead>
<tr>
<th field="user_id"><input type="checkbox" data-target="user_id" class="selectAll"></th>
<th field="username">账号</th>
<th field="name">姓名</th>
<th field="sexn">性别</th>
<th field="mobile">电话</th>
<th field="email">邮箱</th>
<th field="gmt_create">创建时间</th>
<th field="statusn">状态</th></tr>
</thead>
<tbody>

</tbody>
</table>
</div>
<div class="pagination">
</div>
<!-- 新增模态框（Modal） -->
<div class="modal fade" id="userI" tabindex="-1" data-backdrop="static" role="dialog" aria-labelledby="#app" aria-hidden="true"></div>
<!-- 修改模态框（Modal） -->
<div class="modal fade" id="userU" tabindex="-1" data-backdrop="static" role="dialog" aria-labelledby="#app" aria-hidden="true">
</div>
<div class="modal fade" id="userR" tabindex="-1" data-backdrop="static" role="dialog" aria-labelledby="#app" aria-hidden="true">
</div>
<!-- 详细模态框（Modal） -->
<div class="modal fade" id="Udetial" tabindex="-1" data-backdrop="static" role="dialog" aria-labelledby="#app" aria-hidden="true">
	<div class="modal-panel">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
					&times;
				</button>
				<h4 class="modal-title">
					用户详细
				</h4>
			</div>
			<div class="modal-body">
				<form>
				<div class="line">
					<div class="left-48 input-group">
						<span class="input-group-addon">用户姓名</span>
						<input type="text" class="form-control" disabled name="name">
					</div>
					<div class="right-48  input-group">
						<span class="input-group-addon">用户账号</span>
						<input type="text" class="form-control" disabled name="username" value="test">
						
					</div>
				</div>
				<div class="line">
					<div class="left-48 input-group">
						<span class="input-group-addon">状&nbsp;&nbsp;&nbsp;&nbsp;态</span>
						<input class="form-control" disabled name="status"type="text">
					</div>
					<div class="right-48  input-group">
						<span class="input-group-addon">现住址</span>
						<input type="text" class="form-control" disabled name="live_address" placeholder="32个字符或汉字">
					</div>
				</div>
				<div class="line">
					<div class="left-48 input-group">
						<span class="input-group-addon">手&nbsp;&nbsp;&nbsp;&nbsp;机</span>
						<input type="text" class="form-control" disabled name="mobile" placeholder="15个汉字以内">
					</div>
					<div class="right-48 input-group">
						<span class="input-group-addon">邮&nbsp;&nbsp;&nbsp;&nbsp;箱</span>
						<input type="text" class="form-control" disabled name="email" placeholder="16个字符或汉字">
					</div>
				</div>
				<div class="line">
					<div class="left-48 input-group">
						<span class="input-group-addon">性&nbsp;&nbsp;&nbsp;&nbsp;别</span>
						<input class="form-control" disabled name="sex"type="text">
					</div>
					<div class="right-48 input-group">
						<span class="input-group-addon">出生日期</span>
						<input type="text" class="form-control" disabled name="birth" placeholder="格式 年年年年-月月-日日">
					</div>
				</div>
				<div class="line">
					<div class="input-group">
						<span class="input-group-addon">个人爱好</span>
						<div class="ta-outline"><textarea rows="3" disabled name="hobby"></textarea></div>
					</div>
				</div>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭
				</button>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal -->
</div>
<script>


$(document).ready(function(){
	//标签页
	_ptab = $("#userI").getParentTab();

	_ptab.on('click',".add",function(){
		m = getMenuByPermit('admin:user:add');
		$("#userI").load(m.component);
		$("#userI").modal('show');
	});
	
	_ptab.on('click',".edit",function(){
		 m = getMenuByPermit('admin:user:edit');
		 x = $("#userD input[name='user_id']:checked");
		
		if(x.length>=1 && m){
			$("#userU").load(m.component,'',getData(m.url,'user_id='+x.val(),function(res){$("#userU").fillDetailData(res);}));
			$("#userU").modal('show');
		}else{
			messageBox("请先勾选要编辑的用户记录。","操作提示");
		}
	});
	_ptab.on('click',".del",function(){
		 m = getMenuByPermit('admin:user:del');
		 x = $("#userD input[name='user_id']:checked");
		
		if(x.length>=1 && m){
			_p = $(this).getParentTab();
			data = "t="+new Date();
			for(i=0;i<x.length;i++){
				data += "&user_id="+$(x[i]).val();
			}
			getData(m.url,data,function(res){
				if(res.code==RESP_SUCCESS){
					messageBox(res.msg,"操作提示");
					m = getMenuByPermit('admin:user');
					getData(m.url,_p.find("div.searchbar form").serialize(),
					function(res){ _p.fillListData(res); });
				}
			});
			
		}else{
			messageBox("请先勾选要删除的用户记录。","操作提示");
		}
	});
	_ptab.on('click',".enable",function(){
		 m = getMenuByPermit('admin:user:enable');
		 x = $("#userD input[name='user_id']:checked");
		
		if(x.length>=1 && m){
			_p = $(this).getParentTab();
			data = "t="+new Date();
			for(i=0;i<x.length;i++){
				data += "&user_id="+$(x[i]).val();
			}
			getData(m.url,data,function(res){
				if(res.code==RESP_SUCCESS){
					messageBox(res.msg,"操作提示");
					m = getMenuByPermit('admin:user');
					getData(m.url,_p.find("div.searchbar form").serialize(),
					function(res){ _p.fillListData(res); });
				}
			});
			
		}else{
			messageBox("请先勾选要启用的用户记录。","操作提示");
		}
	});
	_ptab.on('click',".forbidden",function(){
		 m = getMenuByPermit('admin:user:forbidden');
		 x = $("#userD input[name='user_id']:checked");
		
		if(x.length>=1 && m){
			_p = $(this).getParentTab();
			data = "t="+new Date();
			for(i=0;i<x.length;i++){
				data += "&user_id="+$(x[i]).val();
			}
			getData(m.url,data,function(res){
				if(res.code==RESP_SUCCESS){
					messageBox(res.msg,"操作提示");
					m = getMenuByPermit('admin:user');
					getData(m.url,_p.find("div.searchbar form").serialize(),
					function(res){ _p.fillListData(res); });
				}
			});
			
		}else{
			messageBox("请先勾选要禁用的用户记录。","操作提示");
		}
	});
	_ptab.on('click',".resetPwd",function(){
		 m = getMenuByPermit('admin:user:resetPwd');
		 x = $("#userD input[name='user_id']:checked");
		
		if(x.length>=1 && m){
			_p = $(this).getParentTab();
			data = "t="+new Date();
			for(i=0;i<x.length;i++){
				data += "&user_id="+$(x[i]).val();
			}
			getData(m.url,data,function(res){
				if(res.code==RESP_SUCCESS){
					messageBox(res.msg,"操作提示");
					m = getMenuByPermit('admin:user');
					getData(m.url,_p.find("div.searchbar form").serialize(),
					function(res){ _p.fillListData(res); });
				}
			});
			
		}else{
			messageBox("请先勾选要重置密码的用户记录。","操作提示");
		}
	});
	_ptab.on('click',".role",function(){
		m = getMenuByPermit('admin:user:role');
		x = $("#userD input[name='user_id']:checked");
		
		if(x.length>=1 && m){
			_p = $("#userR");
			$("#userR").load(m.component,'',getData(m.url,'user_id='+x.val(),function(res){
				if(res.code==RESP_SUCCESS && res.data){
				 _p.find("input[name='user_id']").val(x.val());
					_row = _p.find(".line");
					for(i=0;i<res.data.length;i++){
						$(_row).find("input[name='role_id']").val(res.data[i].role_id);
						$(_row).find("b").text(res.data[i].role_name);
						$(_row).find(".ta-outline>p").text(res.data[i].remark);
						if(i<res.data.length-1){
							_row = _row.clone();
							_row.appendTo(_p.find(".settingform"));
						}
					}
					if(res.checked && res.checked.length>0){
						for(i=0;i<res.checked.length;i++){
							_p.find("input[name='role_id'][value='"+res.checked[i].role_id+"']").prop("checked",true);
						}
					}
				}
			}));
			$("#userR").modal('show');
		}else{
			messageBox("请先勾选要设置角色的用户记录。","操作提示");
		}
	});
	_ptab.on('click',".detail",function(){
		 m = getMenuByPermit('admin:user:get');
		 x = $("#userD input[name='user_id']:checked");
		
		if(x.length>=1 && m){
			getData(m.url,'user_id='+x.val(),function(res){$("#Udetial").fillDetailData(res);});
			$("#Udetial").modal('show');
		}else{
			messageBox("请先勾选要查看详细的用户记录。","操作提示");
		}
	});
 });
</script>